package cn.itcast.tanhua.server.service;

import cn.hutool.core.util.ObjectUtil;
import cn.itcast.tanhua.dubbo.server.api.RecommendUserApi;
import cn.itcast.tanhua.dubbo.server.pojo.RecommendUser;
import cn.itcast.tanhua.dubbo.server.vo.PageInfo;
import cn.itcast.tanhua.server.vo.TodayBest;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName RecommendUserService
 * @Description
 * @Author WU
 * @Date 2021/5/28 16:34
 * @Version 1.0
 */
@Service
public class RecommendUserService {
//    注入服务者功能对象
    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;
    /**
    * @Description: 调用dubbo中的服务者功能，查询今日佳人id及缘分值
    * @Param: id
    * @return:
    * @Author: Mr.Tan
    * @Date: 2021/5/28
    */
    public TodayBest queryTodayBest(Long id) {
        RecommendUser recommendUser = this.recommendUserApi.queryWithMaxScore(id);
        if (null == recommendUser) {
            return null;
        }
//        查到的今日佳人id及缘分值则添加进去
        TodayBest todayBest = new TodayBest();
        todayBest.setId(recommendUser.getUserId());
//        缘分值向下取整
        double score = Math.floor(recommendUser.getScore());
        todayBest.setFateValue(Double.valueOf(score).intValue());

        return todayBest;
    }

    /**
    * @Description: 调用dubbo查询推荐列表
    * @Param:
    * @return:
    * @Author: Mr.Tan
    * @Date: 2021/5/28
    */
    public PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer pagesize) {
        return this.recommendUserApi.queryPageInfo(id,page,pagesize);
    }


    /**
     * 调用dubbo服务查询缘分值
     *
     * @param userId
     * @param id
     * @return
     */
    public Double queryScore(Long userId, Long id) {
        Double score = this.recommendUserApi.queryScore(userId, id);
        if(ObjectUtil.isNotEmpty(score)){
            return score;
        }
        //默认值
        return 98d;
    }

    /**
     * 查询探花列表
     *
     * @param id
     * @param count
     * @return
     */
    public List<RecommendUser> queryCardList(Long id, int count) {
        return this.recommendUserApi.queryCardList(id,count);
    }
}
